package str

func partitionLabels(s string) []int {
	lastPos := make([]int, 26)
	res := []int{}

	for i := range s {
		lastPos[s[i]-'a'] = i
	}

	start, end := 0, 0

	for i, v := range s {
		if lastPos[v-'a'] > end {
			end = lastPos[v-'a']
		}

		if i == end {
			res = append(res, end-start+1)
			start = end + 1
		}
	}

	return res
}
